package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.project.bean.BiaoShuBean;
import com.project.mapper.IBiaoShuMapper;
import com.project.service.IBiaoShuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class BiaoShuServiceImpl implements IBiaoShuService {
    @Autowired
    private IBiaoShuMapper biaoShuMapper;

    @Override
    public void add(BiaoShuBean biaoShuBean) {
        biaoShuMapper.insert(biaoShuBean);
    }

    @Override
    public void updateStatus(Integer biaoShuId) {
        BiaoShuBean biaoShuBean = biaoShuMapper.selectById(biaoShuId);
        biaoShuBean.setStatus("供货完成");
        biaoShuMapper.updateById(biaoShuBean);
    }

    @Override
    public BiaoShuBean findById(Integer biaoShuId) {
        return biaoShuMapper.selectById(biaoShuId);
    }

    @Override
    public double findInPriceByGoodsId(Integer goodsId) {
        QueryWrapper<BiaoShuBean> qw = new QueryWrapper<>();
        qw.eq("fk_goodsId",goodsId);
        BiaoShuBean biaoShuBean = biaoShuMapper.selectOne(qw);
        return biaoShuBean.getPrice();
    }

    @Override
    public void updateInNum(Integer biaoShuId, Integer deltaInNum) {
        BiaoShuBean biaoShuBean = biaoShuMapper.selectById(biaoShuId);
        biaoShuBean.setInNum(biaoShuBean.getInNum()+deltaInNum);
        biaoShuMapper.updateById(biaoShuBean);
    }
}
